package src.Skills;

import src.Main;
import src.Players.*;
import src.Packets.*;
import src.Util.Timer;

public class Woodcutting {
	private int wcXPRate = 1;
	private Player p;
	private Timer t;
	private int[] axeIds = {1351, 1349, 1353, 1355,
				1357, 1359
	};
	private int[] normalLogs = {1511};
	private int[] acheyLogs = {2862};
	private int[] oakLogs = {1521};
	private int[] willowLogs = {1519};
	private int[] teakLogs = {6333};
	private int[] mapleLogs = {1517};
	private int[] mahoganyLogs = {6332};
	private int[] yewLogs = {1515};
	private int[] magicLogs = {1513};
	
	public Woodcutting(Player _p) {
		p = _p;
	}
	
	public void cutTree(int clickId) {
        if(p == null || clickId < 0)
        {
            return;
        }
        if(p.canWalkDelay > 0)
        {
            return;
        }
        int slot = 0;
		int wcLvl = p.skillLvl[8];
		PlayerItems pi = new PlayerItems();
		PlayerChecks pc = new PlayerChecks(p);
		if(!pc.playerHasWeaponArray(p, axeIds)) {
			p.frame.sendMessage(p, "You need an axe to do that!");
			return;
		}
		switch(p.clickId) {
			case 1276:
			case 1277:
			case 1278:
			case 1279:
			case 1280:
			case 1282:
			case 1283:
			case 1284:
			case 1285:
			case 1286:
			case 1287:
			case 1288:
			case 1289:
			case 1290:
			case 1291:
			case 1333:
			case 1365:
			case 1384:
			case 2020:
			case 5902:
			case 5903:
			case 5904:
				if(wcLvl < 1) {
                    p.frame.sendMessage(p, "You need at least 1 Woodcutting to cut a tree.");
                    break;
				} else {
					try {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, normalLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(25 * wcXPRate, 8);
					} catch(Exception e) {
						e.printStackTrace();
					}
				}
			break;
			
			case 2023:
				if(wcLvl < 1) {
                    p.frame.sendMessage(p, "You need at least 1 Woodcutting to cut an Achey tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, acheyLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(25 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 1849:
				if(wcLvl < 15) {
                    p.frame.sendMessage(p, "You need at least 15 Woodcutting to cut an Oak tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, oakLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(37 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 1308:
			case 5551:
			case 5552:
			case 5553:
				if(wcLvl < 30) {
                    p.frame.sendMessage(p, "You need at least 30 Woodcutting to cut a Willow tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, willowLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(67 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 9036:
				if(wcLvl < 35) {
                    p.frame.sendMessage(p, "You need at least 35 Woodcutting to cut a Teak tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, teakLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(85 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 1307:
				if(wcLvl < 45) {
                    p.frame.sendMessage(p, "You need at least 45 Woodcutting to cut a Maple tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, mapleLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(100 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 9034:
				if(wcLvl < 50) {
                    p.frame.sendMessage(p, "You need at least 50 Woodcutting to cut a Mahogany tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, mahoganyLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(125 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 9466:
				if(wcLvl < 60) {
                    p.frame.sendMessage(p, "You need at least 60 Woodcutting to cut a Yew tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
								p.frame.sendMessage(p, "You manage to get some logs!");
								pi.addItem(p, yewLogs[slot], 1);
								p.requestAnim(875, 0);
								p.addSkillXP(175 * wcXPRate, 8);
								p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			case 1306:
				if(wcLvl < 75) {
                    p.frame.sendMessage(p, "You need at least 75 Woodcutting to cut a Magic tree.");
                    break;
				} else {
					for(;;) {
						if(random(8) != 1) {
							p.frame.sendMessage(p, "You manage to get some logs!");
							pi.addItem(p, magicLogs[slot], 1);
							p.requestAnim(875, 0);
							p.addSkillXP(250 * wcXPRate, 8);
							p.canWalkDelay = 5;
						} else {
							break;
						}
					}
				}
			break;
			
			default:
				Main.m.log("[" + p.playerIndex + "-" + p.username + "] Unable to cut tree");
			break;
		}
	}
	
    private int random(int range)
    {
        return (int)(Math.random() * range);
    }
}